package com.xmut.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.LongDao;
import com.sirdc.modules.utils.StringUtils;
import com.xmut.entity.Repair;
import com.xmut.filter.RepairFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *
 */
@Repository
public class RepairDao extends LongDao<Repair>{
    public List<Repair> query(RepairFilter filter) {
        GenericQuery query = createQuery("obj");

        if (StringUtils.isNotBlank(filter.getAddress())){
            query.append(" and obj.address  like :address ");
            query.setParam("address",StringUtils.getLikewords(filter.getAddress()));
        }

        if (StringUtils.isNotBlank(filter.getProblem())){
            query.append(" and obj.problem like :problem ");
            query.setParam("problem",StringUtils.getLikewords(filter.getProblem()));
        }

        if (StringUtils.isNotBlank(filter.getUserId())){
            query.append(" and obj.userId = :userId ");
            query.setParam("userId",filter.getUserId());
        }

        if (StringUtils.isNotBlank(filter.getReplyPeople())){
            query.append(" and obj.replyPeople = :replyPeople ");
            query.setParam("replyPeople",filter.getReplyPeople());
        }

        if (StringUtils.isNotBlank(filter.getReplyState())){
            query.append(" and obj.replyState = :replyState ");
            query.setParam("replyState",filter.getReplyState());
        }

        return query.listResult(filter);
    }

    public List<Repair> queryByUserId(String userId) {
        GenericQuery query = createQuery("obj");
        query.append(" and obj.userId = :userId ");
        query.setParam("userId",userId);
        return query.listResult();

    }
}
